﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html;
using iTextSharp.text.html.simpleparser;
using System.IO;


public partial class frmEmpresa : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        if (Session["tipo_cuenta"] == null)
        {
            Response.Redirect("frm_privilegios.aspx");

            if (Session["tipo_cuenta"].ToString() != "2")  //Si NO es administrador... Redirige a una pagina comun advirtiendo que no posee privilegios suficientes
            {
                Response.Redirect("frm_privilegios.aspx");
            }

        }


        if (Session["cuit"] != null)
        {
            if (!Page.IsPostBack)
            {

                TBCuit.Text = Session["cuit"].ToString();
                this.DSEmpresa.SelectParameters["cuit"].DefaultValue = this.TBCuit.Text;
                this.DSEmpresa.DataSourceMode = SqlDataSourceMode.DataReader;
                SqlDataReader datos = (SqlDataReader)this.DSEmpresa.Select(DataSourceSelectArguments.Empty);


                if (datos.Read())
                {

                    this.TBNomComercial.Text = datos["nombreComercial"].ToString().ToUpper();
                    this.TBRazonSocial.Text = datos["razonSocial"].ToString().ToUpper();
                    this.TBMail.Text = datos["dirCorreo"].ToString();
                    this.TBNumTel.Text = datos["numTelefono"].ToString().ToUpper();
                    this.DropTipoTel.SelectedValue = datos["idTipoTelefono"].ToString();
                    this.DropCondIva.SelectedValue = datos["idCondIva"].ToString();


                    DropLocalidad.DataBind();
                    DropLocalidad.SelectedValue = datos["idLocalidad"].ToString();
                    DropBarrio.DataBind();
                    DropBarrio.SelectedValue = datos["idBarrio"].ToString();

                    this.TBCalle.Text = datos["calle"].ToString().ToUpper();
                    this.TBNumCasa.Text = datos["numeroCalle"].ToString().ToUpper();
                    this.TBPiso.Text = datos["piso"].ToString().ToUpper();
                    this.TBDpto.Text = datos["departamento"].ToString().ToUpper();
                    this.TBCodPostal.Text = datos["codPostal"].ToString();

                    this.DropProvincia.SelectedValue = datos["idProvincia"].ToString();
                    this.DropDownList1.SelectedValue = datos["estado"].ToString();


                    this.TBCuit.ReadOnly = true;
                    this.TBNomComercial.ReadOnly = true;
                    this.TBRazonSocial.ReadOnly = true;
                    this.TBMail.ReadOnly = true;
                    this.TBNumTel.ReadOnly = true;
                    this.DropTipoTel.Enabled = false;
                    this.DropCondIva.Enabled = false;

                    this.TBCalle.ReadOnly = true;
                    this.TBNumCasa.ReadOnly = true;
                    this.TBPiso.ReadOnly = true;
                    this.TBDpto.ReadOnly = true;
                    this.TBCodPostal.ReadOnly = true;
                    this.DropBarrio.Enabled = false;
                    this.DropLocalidad.Enabled = false;
                    this.DropProvincia.Enabled = false;
                    this.DropDownList1.Enabled = false;

                    this.Button3.Enabled = true;
                    this.Button6.Enabled = true;
                    this.Button7.Enabled = true;
                    this.Button8.Enabled = true;
                    this.Button11.Enabled = true;
                    this.Button12.Enabled = true;

                    Session["cuit"] = null;
                }
            }
        }

        else
        {
            this.TBCuit.ReadOnly = false;
            this.TBNomComercial.ReadOnly = true;
            this.TBRazonSocial.ReadOnly = true;
            this.TBMail.ReadOnly = true;
            this.TBNumTel.ReadOnly = true;
            this.DropTipoTel.Enabled = false;
            this.DropCondIva.Enabled = false;

            this.TBCalle.ReadOnly = true;
            this.TBNumCasa.ReadOnly = true;
            this.TBPiso.ReadOnly = true;
            this.TBDpto.ReadOnly = true;
            this.TBCodPostal.ReadOnly = true;
            this.DropBarrio.Enabled = false;
            this.DropLocalidad.Enabled = false;
            this.DropProvincia.Enabled = false;
            this.DropDownList1.Enabled = false;
        
        }

    }
    protected void Button2_Click(object sender, EventArgs e)
    {


        if (this.IsValid)
        {

            this.DSEmpresa.InsertParameters["calle"].DefaultValue = this.TBCalle.Text.ToUpper();
            this.DSEmpresa.InsertParameters["numeroCalle"].DefaultValue = this.TBNumCasa.Text.ToUpper();
            this.DSEmpresa.InsertParameters["piso"].DefaultValue = this.TBPiso.Text.ToUpper();
            this.DSEmpresa.InsertParameters["departamento"].DefaultValue = this.TBDpto.Text.ToUpper();
            this.DSEmpresa.InsertParameters["codPostal"].DefaultValue = this.TBCodPostal.Text.ToUpper();
            this.DSEmpresa.InsertParameters["idBarrio"].DefaultValue = this.DropBarrio.SelectedValue;
            this.DSEmpresa.InsertParameters["idLocalidad"].DefaultValue = this.DropLocalidad.SelectedValue;
            this.DSEmpresa.InsertParameters["idProvincia"].DefaultValue = this.DropProvincia.SelectedValue;
            this.DSEmpresa.InsertParameters["estado"].DefaultValue = this.DropDownList1.SelectedValue;


            this.DSEmpresa.InsertParameters["cuit"].DefaultValue = this.TBCuit.Text.ToUpper();
            this.DSEmpresa.InsertParameters["razonSocial"].DefaultValue = this.TBRazonSocial.Text.ToUpper();
            this.DSEmpresa.InsertParameters["nombreComercial"].DefaultValue = this.TBNomComercial.Text.ToUpper();
            this.DSEmpresa.InsertParameters["dirCorreo"].DefaultValue = this.TBMail.Text;
            this.DSEmpresa.InsertParameters["numTelefono"].DefaultValue = this.TBNumTel.Text.ToUpper();
            this.DSEmpresa.InsertParameters["idTipoTelefono"].DefaultValue = this.DropTipoTel.SelectedValue;
            this.DSEmpresa.InsertParameters["idCondIva"].DefaultValue = this.DropCondIva.SelectedValue;



            this.DSEmpresa.Insert();

            
            Label1.Text = "La Empresa se registro correctamente";

            TBCuit.BackColor = System.Drawing.Color.FromName("#DDEDEE");
            TBNomComercial.BackColor = System.Drawing.Color.FromName("#DDEDEE");
            TBRazonSocial.BackColor = System.Drawing.Color.FromName("#DDEDEE");
            TBMail.BackColor = System.Drawing.Color.FromName("#DDEDEE");
            TBNumTel.BackColor = System.Drawing.Color.FromName("#DDEDEE");
            DropTipoTel.BackColor = System.Drawing.Color.FromName("#DDEDEE");
            DropCondIva.BackColor = System.Drawing.Color.FromName("#DDEDEE");

            this.TBCalle.BackColor = System.Drawing.Color.FromName("#DDEDEE");
            this.TBNumCasa.BackColor = System.Drawing.Color.FromName("#DDEDEE");
            this.TBPiso.BackColor = System.Drawing.Color.FromName("#DDEDEE");
            this.TBDpto.BackColor = System.Drawing.Color.FromName("#DDEDEE");
            this.TBCodPostal.BackColor = System.Drawing.Color.FromName("#DDEDEE");
            this.DropBarrio.BackColor = System.Drawing.Color.FromName("#DDEDEE");
            this.DropLocalidad.BackColor = System.Drawing.Color.FromName("#DDEDEE");
            this.DropProvincia.BackColor = System.Drawing.Color.FromName("#DDEDEE");
            this.DropDownList1.BackColor = System.Drawing.Color.FromName("#DDEDEE");

            this.TBCuit.Text = "";
            TBCuit.ReadOnly = false;
            this.TBNomComercial.Text = "";
            this.TBRazonSocial.Text = "";
            this.TBMail.Text = "";
            this.TBNumTel.Text = "";
            this.DropTipoTel.Enabled = false;
            this.DropCondIva.Enabled = false;


            this.TBCalle.Text = "";
            this.TBNumCasa.Text = "";
            this.TBPiso.Text = "";
            this.TBDpto.Text = "";
            this.TBCodPostal.Text = "";
            this.DropBarrio.Enabled = false;
            this.DropLocalidad.Enabled = false;
            this.DropProvincia.Enabled = false;
            this.DropDownList1.Enabled = false;

        }
        
        
        

    }
    protected void Button1_Click(object sender, EventArgs e)
    {

        if (TBCuit.Text.Equals(""))
            {
             
                Label1.Text = "Ingrese numero de CUIT";

                TBNomComercial.BackColor = System.Drawing.Color.FromName("#DDEDEE");
                TBRazonSocial.BackColor = System.Drawing.Color.FromName("#DDEDEE");
                TBMail.BackColor = System.Drawing.Color.FromName("#DDEDEE");
                TBNumTel.BackColor = System.Drawing.Color.FromName("#DDEDEE");
                DropTipoTel.BackColor = System.Drawing.Color.FromName("#DDEDEE");
                DropCondIva.BackColor = System.Drawing.Color.FromName("#DDEDEE");

                this.TBCalle.BackColor = System.Drawing.Color.FromName("#DDEDEE");
                this.TBNumCasa.BackColor = System.Drawing.Color.FromName("#DDEDEE");
                this.TBPiso.BackColor = System.Drawing.Color.FromName("#DDEDEE");
                this.TBDpto.BackColor = System.Drawing.Color.FromName("#DDEDEE");
                this.TBCodPostal.BackColor = System.Drawing.Color.FromName("#DDEDEE");
                this.DropBarrio.BackColor = System.Drawing.Color.FromName("#DDEDEE");
                this.DropLocalidad.BackColor = System.Drawing.Color.FromName("#DDEDEE");
                this.DropProvincia.BackColor = System.Drawing.Color.FromName("#DDEDEE");
                this.DropDownList1.BackColor = System.Drawing.Color.FromName("#DDEDEE");

               
            }
        else
        {
          
        this.DSEmpresa.SelectParameters["cuit"].DefaultValue = this.TBCuit.Text;
        this.DSEmpresa.DataSourceMode = SqlDataSourceMode.DataReader;
        SqlDataReader datos = (SqlDataReader)this.DSEmpresa.Select(DataSourceSelectArguments.Empty);


        if (datos.Read())
        {

            this.TBNomComercial.Text = datos["nombreComercial"].ToString().ToUpper();
            this.TBRazonSocial.Text = datos["razonSocial"].ToString().ToUpper();
            this.TBMail.Text = datos["dirCorreo"].ToString();
            this.TBNumTel.Text = datos["numTelefono"].ToString().ToUpper();
            this.DropTipoTel.SelectedValue = datos["idTipoTelefono"].ToString();
            this.DropCondIva.SelectedValue = datos["idCondIva"].ToString();


            this.TBCalle.Text = datos["calle"].ToString().ToUpper();
            this.TBNumCasa.Text = datos["numeroCalle"].ToString().ToUpper();
            this.TBPiso.Text = datos["piso"].ToString().ToUpper();
            this.TBDpto.Text = datos["departamento"].ToString().ToUpper();
            this.TBCodPostal.Text = datos["codPostal"].ToString();
            this.DropBarrio.SelectedValue = datos["idBarrio"].ToString();
            this.DropLocalidad.SelectedValue = datos["idLocalidad"].ToString();
            this.DropProvincia.SelectedValue = datos["idProvincia"].ToString();
            this.DropDownList1.SelectedValue = datos["estado"].ToString();


            this.TBCuit.ReadOnly = true;
            this.TBNomComercial.ReadOnly = true;
            this.TBRazonSocial.ReadOnly = true;
            this.TBMail.ReadOnly = true;
            this.TBNumTel.ReadOnly = true;
            this.DropTipoTel.Enabled = false;
            this.DropCondIva.Enabled = false;

            this.TBCalle.ReadOnly = true;
            this.TBNumCasa.ReadOnly = true;
            this.TBPiso.ReadOnly = true;
            this.TBDpto.ReadOnly = true;
            this.TBCodPostal.ReadOnly = true;
            this.DropBarrio.Enabled = false;
            this.DropLocalidad.Enabled = false;
            this.DropProvincia.Enabled = false;
            this.DropDownList1.Enabled = false;

            this.Button3.Enabled = true;
            this.Button6.Enabled = true;
            this.Button7.Enabled = true;
            this.Button8.Enabled = true; 
            this.Button11.Enabled = true;
            this.Button12.Enabled = true;

            TBNomComercial.BackColor = System.Drawing.Color.FromName("#DDEDEE");
            TBRazonSocial.BackColor = System.Drawing.Color.FromName("#DDEDEE");
            TBMail.BackColor = System.Drawing.Color.FromName("#DDEDEE");
            TBNumTel.BackColor = System.Drawing.Color.FromName("#DDEDEE");
            DropTipoTel.BackColor = System.Drawing.Color.FromName("#DDEDEE");
            DropCondIva.BackColor = System.Drawing.Color.FromName("#DDEDEE");

            this.TBCalle.BackColor = System.Drawing.Color.FromName("#DDEDEE");
            this.TBNumCasa.BackColor = System.Drawing.Color.FromName("#DDEDEE");
            this.TBPiso.BackColor = System.Drawing.Color.FromName("#DDEDEE");
            this.TBDpto.BackColor = System.Drawing.Color.FromName("#DDEDEE");
            this.TBCodPostal.BackColor = System.Drawing.Color.FromName("#DDEDEE");
            this.DropBarrio.BackColor = System.Drawing.Color.FromName("#DDEDEE");
            this.DropLocalidad.BackColor = System.Drawing.Color.FromName("#DDEDEE");
            this.DropProvincia.BackColor = System.Drawing.Color.FromName("#DDEDEE");
            this.DropDownList1.BackColor = System.Drawing.Color.FromName("#DDEDEE");
            

            Label1.Text = "";

        }

         
            else
            {
                Label1.Text = "La empresa no está registrada";
                TBCuit.BackColor = System.Drawing.Color.FromName("#DDEDEE");
                TBCuit.ReadOnly = true;
                this.TBNomComercial.Enabled = true;
                this.TBRazonSocial.Enabled = true;
                this.TBMail.Enabled = true;
                this.TBNumTel.Enabled = true;
                this.DropTipoTel.Enabled = true;
                this.DropCondIva.Enabled = true;

                this.TBCalle.Enabled = true;
                this.TBNumCasa.Enabled = true;
                this.TBPiso.Enabled = true;
                this.TBDpto.Enabled = true;
                this.TBCodPostal.Enabled = true;
                this.DropBarrio.Enabled = true;
                this.DropLocalidad.Enabled = true;
                this.DropProvincia.Enabled = true;
                this.DropDownList1.Enabled = true;

                this.TBNomComercial.Text = "";
                this.TBRazonSocial.Text = "";
                this.TBMail.Text = "";
                this.TBNumTel.Text = "";


                this.TBCalle.Text = "";
                this.TBNumCasa.Text = "";
                this.TBPiso.Text = "";
                this.TBDpto.Text = "";
                this.TBCodPostal.Text = "";

                this.Button2.Enabled = true;
                this.Button3.Enabled = false;
                this.Button6.Enabled = false;
                this.Button7.Enabled = false;
                this.Button8.Enabled = false;
                this.Button11.Enabled = false;
                this.Button12.Enabled = false;


                TBNomComercial.BackColor = System.Drawing.Color.White;
                TBRazonSocial.BackColor = System.Drawing.Color.White;
                TBMail.BackColor = System.Drawing.Color.White;
                TBNumTel.BackColor = System.Drawing.Color.White;
                DropTipoTel.BackColor = System.Drawing.Color.White;
                DropCondIva.BackColor = System.Drawing.Color.White;

                this.TBCalle.BackColor = System.Drawing.Color.White;
                this.TBNumCasa.BackColor = System.Drawing.Color.White;
                this.TBPiso.BackColor = System.Drawing.Color.White;
                this.TBDpto.BackColor = System.Drawing.Color.White;
                this.TBCodPostal.BackColor = System.Drawing.Color.White;
                this.DropBarrio.BackColor = System.Drawing.Color.White;
                this.DropLocalidad.BackColor = System.Drawing.Color.White;
                this.DropProvincia.BackColor = System.Drawing.Color.White;
                this.DropDownList1.BackColor = System.Drawing.Color.White;

            }
        }

    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        if (TBCuit.Text.Equals("") || TBNomComercial.Text.Equals(""))
            Label1.Text = "Debe seleccionar una Empresa";

        else
        {

            if (Button3.Text.Equals("Modificar Empresa"))
            {

                this.TBNomComercial.ReadOnly = false;
                this.TBRazonSocial.ReadOnly = false;
                this.TBMail.ReadOnly = false;
                this.TBNumTel.ReadOnly = false;
                this.DropTipoTel.Enabled = true;
                this.DropCondIva.Enabled = true;

                this.TBCalle.ReadOnly = false;
                this.TBNumCasa.ReadOnly = false;
                this.TBPiso.ReadOnly = false;
                this.TBDpto.ReadOnly = false;
                this.TBCodPostal.ReadOnly = false;
                this.DropBarrio.Enabled = true;
                this.DropLocalidad.Enabled = true;
                this.DropProvincia.Enabled = true;
                this.DropDownList1.Enabled = true;

                
                TBNomComercial.BackColor = System.Drawing.Color.White; 
                TBRazonSocial.BackColor = System.Drawing.Color.White;
                TBMail.BackColor = System.Drawing.Color.White;
                TBNumTel.BackColor = System.Drawing.Color.White;
                DropTipoTel.BackColor = System.Drawing.Color.White;
                DropCondIva.BackColor = System.Drawing.Color.White;

                this.TBCalle.BackColor = System.Drawing.Color.White;
                this.TBNumCasa.BackColor = System.Drawing.Color.White;
                this.TBPiso.BackColor = System.Drawing.Color.White;
                this.TBDpto.BackColor = System.Drawing.Color.White;
                this.TBCodPostal.BackColor = System.Drawing.Color.White;
                this.DropBarrio.BackColor = System.Drawing.Color.White;
                this.DropLocalidad.BackColor = System.Drawing.Color.White;
                this.DropProvincia.BackColor = System.Drawing.Color.White;
                this.DropDownList1.BackColor = System.Drawing.Color.White;
                



                Button3.Text = "Guardar Cambios";
                Button3.Font.Bold = true;


            }

            else
            {

                this.DSEmpresa.UpdateParameters["cuit"].DefaultValue = this.TBCuit.Text.ToUpper();
                this.DSEmpresa.UpdateParameters["razonSocial"].DefaultValue = this.TBRazonSocial.Text.ToUpper();
                this.DSEmpresa.UpdateParameters["nombreComercial"].DefaultValue = this.TBNomComercial.Text.ToUpper();
                this.DSEmpresa.UpdateParameters["dirCorreo"].DefaultValue = this.TBMail.Text;
                this.DSEmpresa.UpdateParameters["numTelefono"].DefaultValue = this.TBNumTel.Text.ToUpper();
                this.DSEmpresa.UpdateParameters["idTipoTelefono"].DefaultValue = this.DropTipoTel.SelectedValue;
                this.DSEmpresa.UpdateParameters["idCondIva"].DefaultValue = this.DropCondIva.SelectedValue;
                this.DSEmpresa.UpdateParameters["estado"].DefaultValue = this.DropDownList1.SelectedValue;




                this.DSEmpresa.UpdateParameters["calle"].DefaultValue = this.TBCalle.Text.ToUpper();
                this.DSEmpresa.UpdateParameters["numeroCalle"].DefaultValue = this.TBNumCasa.Text.ToUpper();
                this.DSEmpresa.UpdateParameters["piso"].DefaultValue = this.TBPiso.Text.ToUpper();
                this.DSEmpresa.UpdateParameters["departamento"].DefaultValue = this.TBDpto.Text.ToUpper();
                this.DSEmpresa.UpdateParameters["codPostal"].DefaultValue = this.TBCodPostal.Text.ToUpper();
                this.DSEmpresa.UpdateParameters["idBarrio"].DefaultValue = this.DropBarrio.SelectedValue;
                this.DSEmpresa.UpdateParameters["idLocalidad"].DefaultValue = this.DropLocalidad.SelectedValue;
                this.DSEmpresa.UpdateParameters["idProvincia"].DefaultValue = this.DropProvincia.SelectedValue;

                this.DSEmpresa.Update();


                this.TBCuit.ReadOnly = true;
                this.TBNomComercial.ReadOnly = true;
                this.TBRazonSocial.ReadOnly = true;
                this.TBMail.ReadOnly = true;
                this.TBNumTel.ReadOnly = true;
                this.DropTipoTel.Enabled = false;
                this.DropCondIva.Enabled = false;

                this.TBCalle.ReadOnly = true;
                this.TBNumCasa.ReadOnly = true;
                this.TBPiso.ReadOnly = true;
                this.TBDpto.ReadOnly = true;
                this.TBCodPostal.ReadOnly = true;
                this.DropBarrio.Enabled = false;
                this.DropLocalidad.Enabled = false;
                this.DropProvincia.Enabled = false;
                this.DropDownList1.Enabled = false;


                TBNomComercial.BackColor = System.Drawing.Color.FromName("#DDEDEE");
                TBRazonSocial.BackColor = System.Drawing.Color.FromName("#DDEDEE");
                TBMail.BackColor = System.Drawing.Color.FromName("#DDEDEE");
                TBNumTel.BackColor = System.Drawing.Color.FromName("#DDEDEE");
                DropTipoTel.BackColor = System.Drawing.Color.FromName("#DDEDEE");
                DropCondIva.BackColor = System.Drawing.Color.FromName("#DDEDEE");

                this.TBCalle.BackColor = System.Drawing.Color.FromName("#DDEDEE");
                this.TBNumCasa.BackColor = System.Drawing.Color.FromName("#DDEDEE");
                this.TBPiso.BackColor = System.Drawing.Color.FromName("#DDEDEE");
                this.TBDpto.BackColor = System.Drawing.Color.FromName("#DDEDEE");
                this.TBCodPostal.BackColor = System.Drawing.Color.FromName("#DDEDEE");
                this.DropBarrio.BackColor = System.Drawing.Color.FromName("#DDEDEE");
                this.DropLocalidad.BackColor = System.Drawing.Color.FromName("#DDEDEE");
                this.DropProvincia.BackColor = System.Drawing.Color.FromName("#DDEDEE");
                this.DropDownList1.BackColor = System.Drawing.Color.FromName("#DDEDEE");
                

                Button3.Text = "Modificar Empresa";
                Button3.Font.Bold = false;


            }
        }

    }
   
    protected void Button6_Click(object sender, EventArgs e)
    {
        if (TBCuit.Text.Equals("") || TBNomComercial.Text.Equals(""))
            Label1.Text = "Debe seleccionar una Empresa";

        else
        {
        this.Session["cuit"] = this.TBCuit.Text;
        Response.Redirect("frmContacto.aspx");
        }
        //Response.Redirect("frmContacto.aspx?cuit=" + TBCuit.Text);
    }
    protected void Button7_Click(object sender, EventArgs e)
    {
      /*  if (TBCuit.Text.Equals("") || TBNomComercial.Text.Equals(""))
            Label1.Text = "Debe seleccionar una Empresa";

       
        else{

                if (Button7.Text.Equals("Ver Contactos"))
                {
                    GridContactos.Visible = true;
                    Button7.Text = "Ocultar Contactos";

                    TBNomComercial.BackColor = System.Drawing.Color.FromName("#ccccff");
                    TBRazonSocial.BackColor = System.Drawing.Color.FromName("#ccccff");
                    TBMail.BackColor = System.Drawing.Color.FromName("#ccccff");
                    TBNumTel.BackColor = System.Drawing.Color.FromName("#ccccff");
                    DropTipoTel.BackColor = System.Drawing.Color.FromName("#ccccff");
                    DropCondIva.BackColor = System.Drawing.Color.FromName("#ccccff");

                    this.TBCalle.BackColor = System.Drawing.Color.FromName("#ccccff");
                    this.TBNumCasa.BackColor = System.Drawing.Color.FromName("#ccccff");
                    this.TBPiso.BackColor = System.Drawing.Color.FromName("#ccccff");
                    this.TBDpto.BackColor = System.Drawing.Color.FromName("#ccccff");
                    this.TBCodPostal.BackColor = System.Drawing.Color.FromName("#ccccff");
                    this.DropBarrio.BackColor = System.Drawing.Color.FromName("#ccccff");
                    this.DropLocalidad.BackColor = System.Drawing.Color.FromName("#ccccff");
                    this.DropProvincia.BackColor = System.Drawing.Color.FromName("#ccccff");
                    this.DropDownList1.BackColor = System.Drawing.Color.FromName("#ccccff");
                }
                else
                {
                    GridContactos.Visible = false;
                    Button7.Text = "Ver Contactos";

                    TBNomComercial.BackColor = System.Drawing.Color.FromName("#ccccff");
                    TBRazonSocial.BackColor = System.Drawing.Color.FromName("#ccccff");
                    TBMail.BackColor = System.Drawing.Color.FromName("#ccccff");
                    TBNumTel.BackColor = System.Drawing.Color.FromName("#ccccff");
                    DropTipoTel.BackColor = System.Drawing.Color.FromName("#ccccff");
                    DropCondIva.BackColor = System.Drawing.Color.FromName("#ccccff");

                    this.TBCalle.BackColor = System.Drawing.Color.FromName("#ccccff");
                    this.TBNumCasa.BackColor = System.Drawing.Color.FromName("#ccccff");
                    this.TBPiso.BackColor = System.Drawing.Color.FromName("#ccccff");
                    this.TBDpto.BackColor = System.Drawing.Color.FromName("#ccccff");
                    this.TBCodPostal.BackColor = System.Drawing.Color.FromName("#ccccff");
                    this.DropBarrio.BackColor = System.Drawing.Color.FromName("#ccccff");
                    this.DropLocalidad.BackColor = System.Drawing.Color.FromName("#ccccff");
                    this.DropProvincia.BackColor = System.Drawing.Color.FromName("#ccccff");
                    this.DropDownList1.BackColor = System.Drawing.Color.FromName("#ccccff");
                }
           
        }*/
    }
    protected void Button8_Click(object sender, EventArgs e)
    {
        
        //Response.Redirect("frmEstablecimiento.aspx?cuit=" + TBCuit.Text + "&valor=" +0);
        if (TBCuit.Text.Equals("") || TBNomComercial.Text.Equals(""))
            Label1.Text = "Debe seleccionar una Empresa";

        else
        {
            this.DSEmpresa.SelectParameters["cuit"].DefaultValue = this.TBCuit.Text;
            this.DSEmpresa.DataSourceMode = SqlDataSourceMode.DataReader;
            SqlDataReader datos = (SqlDataReader)this.DSEmpresa.Select(DataSourceSelectArguments.Empty);


            if (datos.Read())
            {

                Session["cuit"] = TBCuit.Text;
                Response.Redirect("frmEstablecimiento.aspx");
            }

            else
                Label1.Text = "Debe seleccionar una Empresa";
        }
        
    }
    protected void GridContactos_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void Button9_Click(object sender, EventArgs e)
    {
        Response.Redirect("frmListaDeEmpresas.aspx");
    }
    protected void Button10_Click(object sender, EventArgs e)
    {
        Response.Redirect("MenuAdministracion.aspx");
    }
    protected void Button11_Click(object sender, EventArgs e)
    {

        if (TBCuit.Text.Equals("")||TBNomComercial.Text.Equals(""))
            Label1.Text = "Debe seleccionar una Empresa";

        else
        {

            FileStream fs = new FileStream(Server.MapPath("~/") + "autorizacion" + TBNomComercial.Text + DateTime.Now.ToString("ddMMyy") + ".pdf", FileMode.Create, FileAccess.Write, FileShare.None);
            Rectangle rec3 = new Rectangle(PageSize.A4);
            Document doc = new Document(rec3, 36, 72, 108, 180);
            PdfWriter writer = PdfWriter.GetInstance(doc, fs);
            iTextSharp.text.Font fontTitle = FontFactory.GetFont("Arial", 18, iTextSharp.text.Font.BOLD, BaseColor.BLACK);
            iTextSharp.text.Font fontHead = FontFactory.GetFont("Arial", 16, iTextSharp.text.Font.BOLD, BaseColor.BLACK);
            iTextSharp.text.Font fontBody = FontFactory.GetFont("Arial", 14, iTextSharp.text.Font.BOLD, BaseColor.BLACK);

            Console.WriteLine("");

            Paragraph titulo = new Paragraph("AUTORIZACION PARA TERCEROS: ", fontTitle);
            titulo.Alignment = Element.ALIGN_JUSTIFIED;


            doc.Open();
            doc.Add(titulo);
            doc.Add(new Paragraph(" "));
            doc.Add(new Paragraph(" "));
            Paragraph cuerpo = new Paragraph("El que suscribe ........................................................... (DNI: ...............................) en su caracter de ................................... de la Firma " + TBRazonSocial.Text + " CUIT: " + TBCuit.Text + " con domicilio en calle " + TBCalle.Text + " Nro. " + TBNumCasa.Text + " Piso " + TBPiso.Text + " Dpto. " + TBDpto.Text + ", hace constar por la presente que el Sr. Fiore Angel Pablo (DNI 16372329), la Srta. Peralta Paola (DNI 31199687) y Srta. Ma. Andrea Zaia (DNI 36806050) domiciliado/a en Obispo Trejo 684, Bº Nueva Cordoba - Ciudad de Cordoba, Telefono 0351-424233, están autorizados a presentar y retirar en la Secretaría de Alimentos del Ministerio de Agricultura, Ganaderia y Alimentos, toda documentacion relacionada con la inscripcion del establecimiento y/o los productos alimenticios pertenecientes a la Firma antes mencionada");
            cuerpo.Alignment = Element.ALIGN_JUSTIFIED;
            doc.Add(cuerpo);
            doc.Add(new Paragraph(" "));
            doc.Add(new Paragraph(" "));
            doc.Add(new Paragraph("Firma: "));
            doc.Add(new Paragraph("Aclaracion y DNI: ............................................ "));
            doc.Add(new Paragraph("Córdoba,  " + DateTime.Now.ToString("dddd dd MMMM yyyy")));
            doc.Add(new Paragraph(" "));
            doc.Add(new Paragraph(" "));
            doc.Add(new Paragraph(" "));
            doc.Add(new Paragraph(" "));
            doc.Add(new Paragraph("DESE A LA TOTALIDAD DE LOS DATOS VOLCADOS EN ESTE FORMULARIO CARACTER DE DECLARACION JURADA"));
            doc.Add(new Paragraph(" "));
            doc.Add(new Paragraph("                                                                        ..........................."));
            doc.Add(new Paragraph("                                                                                   Firma"));

            doc.Close();

            Response.ContentType = "application/pdf";
            Response.AddHeader("Content-Disposition", "attachment;filename=orden" + TBNomComercial.Text + DateTime.Now.ToString("ddMMyy") + ".pdf");
            Response.TransmitFile(Server.MapPath("~/") + "autorizacion" + TBNomComercial.Text + DateTime.Now.ToString("ddMMyy") + ".pdf");

        }

    }
    protected void Button12_Click(object sender, EventArgs e)
    {
        if (TBCuit.Text.Equals("") || TBNomComercial.Text.Equals(""))
            Label1.Text = "Debe seleccionar una Empresa";

        else
        {
            FileStream fs = new FileStream(Server.MapPath("~/") + "solicitudRNE" + TBNomComercial.Text + DateTime.Now.ToString("ddMMyy") + ".pdf", FileMode.Create, FileAccess.Write, FileShare.None);
            Rectangle rec3 = new Rectangle(PageSize.A4);
            Document doc = new Document(rec3, 36, 72, 108, 180);
            PdfWriter writer = PdfWriter.GetInstance(doc, fs);
            iTextSharp.text.Font fontTitle = FontFactory.GetFont("Arial", 18, iTextSharp.text.Font.BOLD, BaseColor.BLACK);
            iTextSharp.text.Font fontHead = FontFactory.GetFont("Arial", 16, iTextSharp.text.Font.BOLD, BaseColor.BLACK);
            iTextSharp.text.Font fontBody = FontFactory.GetFont("Arial", 14, iTextSharp.text.Font.BOLD, BaseColor.BLACK);

            Console.WriteLine("");

            doc.Open();

            Paragraph fecha = new Paragraph(" Cordoba, " + DateTime.Now.ToString("dddd dd MMMM yyyy"));
            fecha.Alignment = Element.ALIGN_RIGHT;
            doc.Add(fecha);
            doc.Add(new Paragraph(" "));
            doc.Add(new Paragraph(" "));
            doc.Add(new Paragraph("Al Sr. Secretario "));
            doc.Add(new Paragraph("Ministerio de Agricultura, Ganaderia y Alimentos "));
            doc.Add(new Paragraph("Secretaria de Alimentos "));
            doc.Add(new Paragraph("Cr. Fontana Fernando José "));
            doc.Add(new Paragraph("S______/______D "));
            doc.Add(new Paragraph(" "));
            doc.Add(new Paragraph(" "));
            Paragraph cuerpo = new Paragraph("El que suscribe ........................................................... (DNI: ...............................) en su caracter de ................................... de la Firma " + TBRazonSocial.Text + " CUIT: " + TBCuit.Text + " con domicilio en calle " + TBCalle.Text + " Nro. " + TBNumCasa.Text + " Piso " + TBPiso.Text + " Dpto. " + TBDpto.Text + ", se dirige a Ud. a fin de solicitarle la Inscripcion del Registro Nacional de Establecimiento");
            cuerpo.Alignment = Element.ALIGN_JUSTIFIED;
            doc.Add(cuerpo);
            doc.Add(new Paragraph(" "));
            doc.Add(new Paragraph(" "));
            doc.Add(new Paragraph("Atentamente "));
            doc.Add(new Paragraph(" "));
            doc.Add(new Paragraph(" "));
            doc.Add(new Paragraph(" "));
            doc.Add(new Paragraph(" "));
            doc.Add(new Paragraph(" "));
            doc.Add(new Paragraph("                                                                        ..........................."));
            doc.Add(new Paragraph("                                                                                   Firma"));
            doc.Add(new Paragraph(" "));
            doc.Add(new Paragraph("                                                                ............................................"));
            doc.Add(new Paragraph("                                                                             Aclaracion - DNI"));
            doc.Add(new Paragraph("                                                                          Certificada la Firma"));

            doc.Close();

            Response.ContentType = "application/pdf";
            Response.AddHeader("Content-Disposition", "attachment;filename=orden" + TBNomComercial.Text + DateTime.Now.ToString("ddMMyy") + ".pdf");
            Response.TransmitFile(Server.MapPath("~/") + "solicitudRNE" + TBNomComercial.Text + DateTime.Now.ToString("ddMMyy") + ".pdf");


        }

    }
    protected void Button13_Click(object sender, EventArgs e)
    {

        this.TBNomComercial.ReadOnly = false;
        this.TBRazonSocial.ReadOnly = false;
        this.TBMail.ReadOnly = false;
        this.TBNumTel.ReadOnly = false;
        this.DropTipoTel.Enabled = true;
        this.DropCondIva.Enabled = true;

        this.TBCuit.ReadOnly = false;
        this.TBCalle.ReadOnly = false;
        this.TBNumCasa.ReadOnly = false;
        this.TBPiso.ReadOnly = false;
        this.TBDpto.ReadOnly = false;
        this.TBCodPostal.ReadOnly = false;
        this.DropBarrio.Enabled = true;
        this.DropLocalidad.Enabled = true;
        this.DropProvincia.Enabled = true;
        this.DropDownList1.Enabled = true;

        this.TBNomComercial.Text = "";
        this.TBRazonSocial.Text = "";
        this.TBMail.Text = "";
        this.TBNumTel.Text = "";

        this.TBCuit.Text = "";
        this.TBCalle.Text = "";
        this.TBNumCasa.Text = "";
        this.TBPiso.Text = "";
        this.TBDpto.Text = "";
        this.TBCodPostal.Text = "";
        this.Label1.Text = "";

        this.Button2.Enabled = true;
        this.Button3.Enabled = false;
        this.Button6.Enabled = false;
        this.Button7.Enabled = false;
        this.Button8.Enabled = false;
        this.Button11.Enabled = false;
        this.Button12.Enabled = false;

        TBCuit.BackColor = System.Drawing.Color.FromName("#DDEDEE");                
        TBNomComercial.BackColor = System.Drawing.Color.FromName("#DDEDEE");
        TBRazonSocial.BackColor = System.Drawing.Color.FromName("#DDEDEE");
        TBMail.BackColor = System.Drawing.Color.FromName("#DDEDEE");
        TBNumTel.BackColor = System.Drawing.Color.FromName("#DDEDEE");
        DropTipoTel.BackColor = System.Drawing.Color.FromName("#DDEDEE");
        DropCondIva.BackColor = System.Drawing.Color.FromName("#DDEDEE");

        this.TBCalle.BackColor = System.Drawing.Color.FromName("#DDEDEE");
        this.TBNumCasa.BackColor = System.Drawing.Color.FromName("#DDEDEE");
        this.TBPiso.BackColor = System.Drawing.Color.FromName("#DDEDEE");
        this.TBDpto.BackColor = System.Drawing.Color.FromName("#DDEDEE");
        this.TBCodPostal.BackColor = System.Drawing.Color.FromName("#DDEDEE");
        this.DropBarrio.BackColor = System.Drawing.Color.FromName("#DDEDEE");
        this.DropLocalidad.BackColor = System.Drawing.Color.FromName("#DDEDEE");
        this.DropProvincia.BackColor = System.Drawing.Color.FromName("#DDEDEE");
        this.DropDownList1.BackColor = System.Drawing.Color.FromName("#DDEDEE");

    }


    protected void DropLocalidad_SelectedIndexChanged(object sender, EventArgs e)
    {
         DropBarrio.Enabled = true;

    }
    protected void DropProvincia_SelectedIndexChanged(object sender, EventArgs e)
    {
        DropLocalidad.Enabled = true;
        DropBarrio.Enabled = false;
      
    }
}